<template>
  <div>
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
    >
      <el-menu-item index="1">首页</el-menu-item>
      <el-menu-item index="2">博客管理</el-menu-item>
      <el-menu-item index="3">题库管理</el-menu-item>
    </el-menu>
    <div
      style="
        width: 100%;
        height: 800px;
        background-color: #fff;
        border-bottom-right-radius: 8px;
        border-bottom-left-radius: 8px;
      "
    >
      <div style="padding: 10px">
        <h1>审核博客</h1>
      </div>
      <div
        style="
          margin-left: 80px;
          width: 70%;
          height: 680px;
          overflow-x: hidden;
          overflow-y: auto;
          background-color: rgb(72, 155, 194);
        "
      >
        <div v-for="i in BlogInfo.length" :key="i">
          <div class="blog_box">
            <div class="title">
              <span>{{ BlogInfo[i - 1].blogTitle }}</span>
            </div>
            <div class="note" v-on:click="opena(BlogInfo[i - 1].blogId)">
              <span>{{ BlogInfo[i - 1].blogNote }}</span>
            </div>
            <div class="username">
              <span>用户名：{{ BlogInfo[i - 1].userName }}</span>
              <span style="margin-left: 480px">{{
                BlogInfo[i - 1].createTime
              }}</span>
              <button class="tongguo" v-on:click="pass(BlogInfo[i - 1].blogId)">
                通过
              </button>
              <button
                class="weitongguo"
                v-on:click="nopass(BlogInfo[i - 1].blogId)"
              >
                未通过
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      activeIndex: "2",
      BlogInfo: [],
    };
  },
  mounted() {
    this.GetCheckBlogInfo();
  },
  methods: {
    handleSelect(key) {
      if (key == 2) {
        this.$message({
          message: "请不用重复点击同一个路由！！",
          type: "warning",
        });
      } else if (key == 1) {
        this.$router.push("/index");
      } else if (key == 3) {
        this.$router.push("/question");
      }
    },
    GetCheckBlogInfo() {
      axios.get("http://localhost:8888/GetCheckBlogInfo").then((response) => {
        console.log(response.data);
        this.BlogInfo = response.data;
      });
    },
    opena(blogId) {
      window.open("http://www.ltx1226.cn/#/BlogView?blogId=" + blogId);
    },
    pass(blogId) {
      axios
        .post("http://localhost:8888/pass", { blogId: blogId })
        .then((response) => {
          for (var i = 0; i < this.BlogInfo.length; i++) {
            if (this.BlogInfo[i].blogId == blogId) {
              this.BlogInfo.splice(i, 1);
            }
          }
        });
    },
    nopass(blogId) {
      axios
        .post("http://localhost:8888/nopass", { blogId: blogId })
        .then((response) => {
          for (var i = 0; i < this.BlogInfo.length; i++) {
            if (this.BlogInfo[i].blogId == blogId) {
              this.BlogInfo.splice(i, 1);
            }
          }
        });
    },
  },
};
</script>

<style>
.blog_box {
  margin-left: 100px;
  margin-top: 15px;
  width: 80%;
  height: 120px;
  background-color: rgb(231, 231, 231);
  position: relative;
  border-radius: 5px;
  padding: 6px;
}
.blog_box span {
  font-size: 2.3px;
}
.note {
  margin-top: 4px;
}
.username {
  margin-top: 15px;
  margin-left: 5px;
}
.tongguo {
  position: absolute;
  right: 130px;
}
.weitongguo {
  position: absolute;
  right: 50px;
}
</style>